//# sourceURL=http://uMapApp/Module/Bridge/Bridge
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../../UI/Layer"
    , "../../Earth/ViewPort"
    , "../StakeNum/StakeNum"
], function (
    mhjs,
    uMap,
    uEarth,
    Layer,
    ViewPort,
    StakeNum
) {

    function Bridge(option) {
        var _this = this;
        option && _this.OptionToProperties(option);

        if (_this.position) {

            _this.startStakeNum = StakeNum.transform(_this["开始桩号"]);
            _this.stopStakeNum = StakeNum.transform(_this["结束桩号"]);

            _this.stakeNum = _this.startStakeNum;

            _this.title = _this["名称"];
            _this.searchKey = _this["名称"] + " " + _this["类型"] + " " + _this["朝向"];
            _this.sortKey = _this.startStakeNum.distance;

            _this.layer = new Layer({
                "dataSource" : _this.dataSource,
                "app"        : _this.app
            });

            // _this.layer.dataSourceView.on("loaded", function () {
            //     _this.layer.dataSourceView.close();
            // });

            // var styles = {
            //     highlight : "color('yellow',1)",
            //     active    : "color('red',1)"
            // };
            //
            // _this.layer.dataSourceView.tileSet.on("mouseOver", function (event) {
            //
            //     if (event.pickObjectStop) {
            //         var feature = event.pickObjectStop;
            //         if (feature.getProperty("ELEMENT_ID")) {
            //             _this.layer.dataSourceView.setStyle([{
            //                 tag   : "ELEMENT_ID",
            //                 value : feature.getProperty("ELEMENT_ID"),
            //                 style : styles.highlight
            //             }]);
            //         }
            //     }
            //
            // });
            //
            // _this.layer.dataSourceView.tileSet.on("click", function (event) {
            //
            //     if (event.pickObject) {
            //         var feature = event.pickObject;
            //         if (feature.getProperty("ELEMENT_ID")) {
            //             _this.layer.dataSourceView.setStyle([{
            //                 tag   : "ELEMENT_ID",
            //                 value : feature.getProperty("ELEMENT_ID"),
            //                 style : styles.active
            //             }]);
            //
            //             _this.trigger("elementSelect", feature.getProperty("ELEMENT_ID"));
            //         }
            //     }
            //
            // });

            _this.marker = new uMap.Entity({
                objectOption : {
                    position  : _this.position,
                    billboard : new uMap.BillboardGraphic({
                        objectOption : {
                            image          : _this.app.icons.getIconMarker(_this.app.icons.bridge),
                            verticalOrigin : "BOTTOM"
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    }),
                    label     : new uMap.LabelGraphic({
                        objectOption : {
                            text           : _this["名称"],
                            verticalOrigin : "TOP"
                            , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                    })
                }
            });
            _this.layer.dataSources.entities.add(_this.marker.object);
        }


    }

    var _class = Bridge;

    mhjs.OptionToPropertiesInterface(_class);
    mhjs.EventInterface(_class);

    Object.defineProperties(_class.prototype, {
        "open"   : {
            value : function () {
                if (!this.isOpened) {
                    this.layer && this.layer.open();
                    this.isOpened = true;
                    this.trigger("open");
                }
            }
        },
        "close"  : {
            value : function () {
                if (this.isOpened) {
                    this.layer && this.layer.close();
                    this.isOpened = false;
                    this.trigger("close");
                }
            }
        },
        "toggle" : {
            value : function () {
                if (this.isOpened) {
                    this.close();
                } else {
                    this.open();
                }
            }
        },
        "active" : {
            value : function (isActive) {
                var _this = this;

                isActive = (isActive === undefined) || Boolean(isActive);
                _this.isActive = _this.isActive === undefined ? false : _this.isActive;

                if (isActive !== _this.isActive) {

                    if (isActive) {

                        if (_this.layer) {
                            // _this.layer.active();
                            // _this.layer.dataSourceView.open();
                        }

                        _this.marker.label.fillColor = new uMap.Color(["#ff0"]);
                        _this.marker.label.scale = 1.2;
                        _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.app.icons.bridge, true);

                        _this.trigger("active");

                    } else {

                        if (_this.layer) {
                            // _this.layer.dataSourceView.close();
                        }

                        _this.marker.label.fillColor = new uMap.Color(["#FFF"]);
                        _this.marker.label.scale = 1;
                        _this.marker.billboard.image = _this.app.icons.getIconMarker(_this.app.icons.bridge);

                        _this.trigger("unActive");
                    }

                    _this.isActive = isActive;

                }


            }
        }
    });

    return _class;

});